package guowei.ssoclientone.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class NotLogin {

    @Value("${login.url}")
    private String serverurl;

// 未登录，此时需要跳转到登陆页面
    @GetMapping("/login")
    public String gethello(Model model, HttpSession session,
                           @RequestParam(value = "token",required = false) String token){
        if (!StringUtils.isEmpty(token)){
            session.setAttribute("loginUser",token);
        }
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser == null){
            return "redirect://"+serverurl+"?url=client2.com:9502/login";
        }else {
            System.out.println(loginUser);
            ArrayList<String> list = new ArrayList<>();
            list.add("zs");
            list.add("ls");
            model.addAttribute("emps",list);
            return "login";
        }
    }
}
